package com.simulation.web.service.impl;

import com.simulation.common.utils.SecurityUtils;
import com.simulation.web.domain.TechFavorite;
import com.simulation.web.mapper.FavoriteMapper;
import com.simulation.web.service.FavoriteService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
public class FavoriteServiceImpl implements FavoriteService {

    private final FavoriteMapper favoriteMapper;

    /**
     * 查询所有记录
     *
     * @return 返回集合，没有返回空List
     */
    @Override
    public List<TechFavorite> listAll() {
    	return favoriteMapper.listAll();
    }


    /**
     * 根据主键查询
     *
     * @param id 主键
     * @return 返回记录，没有返回null
     */
    @Override
    public TechFavorite getById(Long id) {
    	return favoriteMapper.getById(id);
    }
	
    /**
     * 新增，插入所有字段
     *
     * @param techFavorite 新增的记录
     * @return 返回影响行数
     */
    @Override
    public int insert(TechFavorite techFavorite) {
    	return favoriteMapper.insert(techFavorite);
    }
	
    /**
     * 新增，忽略null字段
     *
     * @param techFavorite 新增的记录
     * @return 返回影响行数
     */
    @Override
    public int insertIgnoreNull(TechFavorite techFavorite) {
        techFavorite.setUserId(SecurityUtils.getUserId());
    	return favoriteMapper.insertIgnoreNull(techFavorite);
    }
	
    /**
     * 修改，修改所有字段
     *
     * @param techFavorite 修改的记录
     * @return 返回影响行数
     */
    @Override
    public int update(TechFavorite techFavorite) {
    	return favoriteMapper.update(techFavorite);
    }
	
    /**
     * 修改，忽略null字段
     *
     * @param techFavorite 修改的记录
     * @return 返回影响行数
     */
    @Override
    public int updateIgnoreNull(TechFavorite techFavorite) {
    	return favoriteMapper.updateIgnoreNull(techFavorite);
    }
	
    /**
     * 删除记录
     *
     * @param techFavorite 待删除的记录
     * @return 返回影响行数
     */
    @Override
    public int delete(TechFavorite techFavorite) {
        techFavorite.setUserId(SecurityUtils.getUserId());
    	return favoriteMapper.delete(techFavorite.getPostId(), techFavorite.getUserId());
    }
}